import requests
import execjs

from util.timestamp import get_timestamp

with open('./parse/洋码头.js') as f:
    js_str = f.read()
    js_code = execjs.compile(js_str, cwd="./parse")

v = {
    "format": "json",
    "appid": 77,
    "requestid": js_code.call('guid') ,
    "accesstoken": "",
    "userid": "",
    "idfa": "860d8e73-c1da-151d-1632-f95662271767",
    "imei": "860d8e73-c1da-151d-1632-f95662271767",
    "mchId": 504443195,
    "mchEEId": "",
    "sid": "",
    "language": "zh_CN"
}

print(get_timestamp())

# _gcl_au=1.1.1949500148.1764032458; _ga=GA1.1.1665770841.1764032468; _ga_GXZMXL96VN=GS2.1.s1764058814$o2$g1$t1764058857$j17$l0$h2118148133
# _gcl_au=1.1.1949500148.1764032458; _ga=GA1.1.1665770841.1764032468; _ga_GXZMXL96VN=GS2.1.s1764058814$o2$g1$t1764058920$j16$l0$h2118148133
res = requests.post('https://www.ymatou.com/api/nodesearch/sqsearch',json={
    "pageIndex": 1,
    "sortType": 1,
    "sortMode": 0,
    "refreshProduct": "true",
    "keyword": "手表"
},headers={
    'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36',
    'referer':'https://www.ymatou.com/search?keyword=%E6%89%8B%E8%A1%A8',
    'ymt-pars':js_code.call('get_params',v),
    'cookie':f'_gcl_au=1.1.1949500148.1764032458; _ga=GA1.1.1665770841.1764032468; _ga_GXZMXL96VN=GS2.1.s1764058814$o2$g1$t{get_timestamp()//1000}$j{2}$l0$h2118148133'
})
print(js_code.call('get_params', v))
print(res.json(), get_timestamp()//1000)

